package Towary;

import java.util.ArrayList;

public class Przechowalnia {

        //public static ArrayList<Towar> lista = new ArrayList<>();
        
        boolean towarZapisany = true;
        Towar t;
        
        public synchronized void dodajTowar(int id, int waga){          
                try {
                        while(towarZapisany==false){
                                wait();
                        }
                } catch (InterruptedException e) {
                        e.printStackTrace();
                }
                //System.out.println("tworze nowy towar id:"+ id);
                t = new Towar(id);
                t.zapiszWage(waga);
                towarZapisany=false;
                notifyAll();
        }
        
        
        public synchronized Towar pobierzTowar(){               
                try {
                        while(towarZapisany==true){
                                wait();
                        }
                } catch (InterruptedException e) {
                        e.printStackTrace();
                }
                towarZapisany=true;
                notifyAll();
                return t;
        }
        
        

}